﻿using System;
using System.Drawing;
using QuantumFractals;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace QuantumFractals.Tests
{
    [TestClass()]
    public class QFractalTest
    {
        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void BitmapTest()
        {
            const int resolution = 800;

            Color[,] c = new Color[resolution, resolution];
            int t1 = Environment.TickCount;
            for (int x = 0; x < resolution; x++)
                for (int y = 0; y < resolution; y++)
                    c[x, y] = Color.Black;
            t1 = Environment.TickCount - t1;
            Assert.IsTrue(t1 < 100, "Zbyt długi czas wykonania dla tablicy {0} [Ms]", t1);

            Bitmap b = new Bitmap(resolution, resolution);
            int t2 = Environment.TickCount;
            for (int x = 0; x < b.Width; x++)
                for (int y = 0; y < b.Height; y++)
                    b.SetPixel(x, y, Color.Black);
            t2 = Environment.TickCount - t2;
            Assert.IsTrue(t2 < 2000, "Zbyt długi czas wykonania dla bitmapy {0} [Ms]", t2);

             Assert.IsTrue(t1 < t2);
        }

        [TestMethod()]
        public void CalculateStepTest()
        {
            QFractal qf = new QFractal(0.61803398874989288039384209090709,
                new QPoint[] {
                    new QPoint(0, 0, 1.0), 
                    new QPoint(0.9428090415820634,0,-0.3333333333333333),
                    new QPoint(-0.4714045207910317,0.816496580927726,-0.3333333333333333),
                    new QPoint(-0.4714045207910317, -0.816496580927726, -0.3333333333333333)});

            int t = Environment.TickCount;
            for (int i = 0; i < 1000000; i++)
                qf.CalculateNextPoint();
            Assert.IsTrue(Environment.TickCount - t < 1000, 
                "Zbyt długi czas wykonania {0} [Ms]", Environment.TickCount - t);
        }
    }
}
